package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sc.nft.enums.PushTypeEnum;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.PushRecord;
import com.sc.nft.mapper.PushRecordMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * (sc_push_record)数据DAO
 *
 * @author Sun
 * @since 2022-09-06 14:27:28
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class PushRecordDao extends ServiceImpl<PushRecordMapper, PushRecord> {

    public PushRecord getListByTypeAndProductId(PushTypeEnum pushType, Long productId) {
        LambdaQueryWrapper<PushRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(PushRecord::getProductId,productId);
        wrapper.eq(PushRecord::getPushType,pushType);
        return getOne(wrapper);
    }


    public List<PushRecord> getListByType(PushTypeEnum pushType) {
        LambdaQueryWrapper<PushRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(PushRecord::getPushType,pushType);
        wrapper.last("order by id desc");
        return list(wrapper);
    }
}